package com.hfdg.authority.ctrl;

import com.hfdg.authority.model.AuthMenuTreeNode;
import com.hfdg.prototype.base.model.AjaxResult;
import com.hfdg.authority.entity.AuthMenu;
import com.hfdg.authority.service.AuthMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.Model;

import java.util.List;

/**
 * @ClassName AuthMenuCtrl
 * @Description TODO
 * @Author yuelh
 * @Date 2020/01/30 11:57:46
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Controller
@RequestMapping("/authMenu")
public class AuthMenuCtrl {
    @Autowired
    AuthMenuService authMenuService;

     /**
     * @Author: yuelh
     * @Description:  TODO 保存数据
     * @Date:  2020/01/30 23:57:46
     * @Param: authMenu
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save (AuthMenu authMenu){
        if(null!=authMenu.getUid()&&!"".equals(authMenu.getUid().trim())){
            authMenuService.update(authMenu);
        }else{
           authMenuService.insert(authMenu);
        }
        return AjaxResult.success();
    }
     /**
     * @Author: yuelh
     * @Description:  TODO 根据UID删除数据
     * @Date:  2020/01/30 23:57:46
     * @Param: uid 要删除的数据条目的uid
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String uid){
            authMenuService.delete(uid);
            return AjaxResult.success();
    }
    /**
         * @Author: yuelh
         * @Description:  TODO 根据UID删除数据
         * @Date:  2020/01/30 23:57:46
         * @Param: uid 要删除的数据条目的uid
         * @return: com.hfdg.base.domains.AjaxResult
         **/
        @RequestMapping("/batchRemove")
        @ResponseBody
        public AjaxResult batchRemove(@RequestParam("uids[]") String[] uids){
                 authMenuService.batchDelete(uids);
                return AjaxResult.success();
        }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表
     * @Date:  2020/01/30 23:57:46
     * @Param: authMenu 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/list")
    @ResponseBody
    public  AjaxResult list(AuthMenu authMenu){
        return AjaxResult.success(authMenuService.list(authMenu));
    }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表,分页
     * @Date:  2020/01/30 23:57:46
     * @Param: offset 数据偏移值，limit 单页最大记录数，orderBy 排序字段 ，authMenu 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/getPagingData")
    @ResponseBody
    public AjaxResult getPagingData(Integer offset,Integer limit,String orderBy,AuthMenu authMenu){
        System.out.println(authMenu.getName());
        return  AjaxResult.success(authMenuService.getPagingData(offset,limit,orderBy,authMenu));
    }

     /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至表单页面
     * @Date:  2020/01/30 23:57:46
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toCreateView")
    public String toForm(HttpServletRequest request, HttpServletResponse response,Model model){
        return "commons/"+"authority"+"/"+"authMenuCreateView";
    }

/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至编辑页面
     * @Date:  2020/01/30 23:57:46
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toEditView")
    public String toEditView(HttpServletRequest request, HttpServletResponse response,String uid,Model model){
            AuthMenu authMenu= authMenuService.get(uid);
            model.addAttribute("formData",authMenu);
            return "commons/"+"authority"+"/"+"authMenuEditView";
        }


/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至对应列表页面
     * @Date:  2020/01/30 23:57:46
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toListView")
    public String toListView(HttpServletRequest request, HttpServletResponse response,Model model){
        return "commons/"+"authority"+"/"+"authMenuListView";
    }

    /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转
     * @Date:  2020/01/30 23:57:46
     * @Param: page  要跳转的页面
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/view/{page}")
    public String view(HttpServletRequest request, HttpServletResponse response, @PathVariable("page") String page){
        return "commons/"+"authority"+"/"+page;
    }

    @RequestMapping("/listMenuTree")
    @ResponseBody
    public Object listMenuTree(AuthMenu authMenu){
        return authMenuService.listMenuTree(authMenu);
    }
    @RequestMapping("/buildLeftMenuBar")
    @ResponseBody
    public List<AuthMenuTreeNode> buildLeftMenuBar(AuthMenu authMenu){
        return authMenuService.buildLeftMenuBar(authMenu);
    }


}
